package cate.game.role.res.guild.po.treasurehouse.msg;

import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgOutput;
import cate.game.client.msg.id.MsgIdGuild;
import cate.game.role.Role;
import cate.game.role.res.guild.po.treasurehouse.GuildTreasureItem;
import easy.java.dev.note.NoteField;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@NoArgsConstructor
@ClientMsg(title = "公会宝库信息 の 返回")
public class GuildTreasureHouseResp implements MsgOutput {
    @NoteField("一天放入宝库多少次")
    public int putInTimes;
    @NoteField("某某商品购买了多少次")
    public Map<Integer, Integer> takeOutTimesMap;
    @NoteField(value = "公会宝库信息")
    public Map<Integer, GuildTreasureItem> itemMap;

    public GuildTreasureHouseResp(Role role) {
        putInTimes = role.getRes().guild.treasureHouse.putInTimes;
        takeOutTimesMap = role.getRes().guild.treasureHouse.takeOutTimesMap;
        itemMap = Optional.ofNullable(role.getRes().guild.getGuild())
                .map(guildPO -> guildPO.treasureHouse.itemMap)
                .orElse(new HashMap<>());
    }

    @Override
    public MsgConfig conf() {
        return MsgIdGuild.GUILD_TREASURE_HOUSE_RESP;
    }
}
